// pages/server_end/editinfo/editinfo.js
const app = getApp();
const request = require('../../../utils/request.js');
const url = require('../../../utils/url.js');
const cookie = require('../../../utils/cookie.js');

Page({
  /**
   * 页面的初始数据
   */
  data: {
    contact_name: "",
    contact_tel: "",
    postcode: "",
    addr:"",
    addr_detail: "",
    sevice_category_id: 0,
    desc: "",
    setlocation:0,
    lat:0,
    lng:0,
    uploadfront: 0,
    uploadback: 0,
    idcard_front_image: "",
    idcard_front_image_url: "/static/icon/icon_upload_id1.png",
    idcard_back_image: "",
    idcard_back_image_url: "/static/icon/icon_upload_id2.png",
    regionValue: '',
    serverType:"",
    serverTypeRange: [],
    servicetaglist:[],
    taglist:[],
    tagIds:[],
    imgs: [],
    picList: [],
    token: "",
    show: 0,
    show1: false,
	curcity:'',
	citytxt:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
	console.log("================");
	console.log(options);
	that.setData({
	  curcity: options.city
	})
    cookie.getCookie('userInfo', function (res) {
      if (res) {
        var etime = Date.parse(new Date()) / 1000;
        
        if (etime < res.expiretime) {
          that.setData({
            login: 1,
            token:res.token
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  regionChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
       postcode:e.detail.postcode,
       regionValue:e.detail.value.join(''),
	   citytxt:e.detail.value[1]
    })
  },
  choselocation(){
    var that = this;
    wx.chooseLocation({
      success: function(res) {
        console.log("地图点击事件：" + JSON.stringify(res));
        that.setData({
          addr:res.address,
          lat : res.latitude,
          lng: res.longitude,
          setlocation:1 
        });

      }
    })
  },
 save(){
	 
	 var city =this.data.citytxt;
	 console.log('citytxt:'+this.data.citytxt);
  var that = this;
  if (!city) {
    wx.showToast({
      title: '请选择城市',
      icon:'none'
    })
    return false;
  }
  
  let param = {
    scoure: 'wxapp',
    token:that.data.token,
    city: city
  }
  wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
  request.request(url.update_user_apply_city, param, url.REQUEST_METHOD_POST).then((res) => {
    wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
    wx.showToast({
      title: res.data.msg,
      icon:"none"
    });
    if(res.data.code==1){
      setTimeout(function() {
        wx.navigateBack({
          delta: 2
        })
      }, 1500)
      return false;
     }
  })  	
 }
})